#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <math.h>

#define INT32 int
//#define DIAGDL_RESULT_FILE "/tmp/.diagdl_result.txt"
#define DIAGDL_RESULT_FILE "./diagdl_result.txt"
#define DIAGDL_FILE "/tmp/diagdl_file"

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

void download_diagnostics_start()
{

}

INT32 download_diagnostic_get(char *name, char *value)
{   
	FILE *fp = NULL; 
	char buff[512] = {0};
	char key[256]={0};
	char val[256]={0};

	fp = fopen(DIAGDL_RESULT_FILE, "r");

	if(fp == NULL){
		printf("open %s failed\n", DIAGDL_RESULT_FILE);
		return -1;
	}

	while(fgets(buff, sizeof(buff), fp)){
		//printf("buff=[%s]\n", buff);
		if( 2 == sscanf(buff, "%[^=]=%[^\n]\n", key, val)){
			//printf("name=[%s], val=[%s]\n", key, val);
			if(!strcmp(key, name)){
				strcpy(value, val);
				break;
			}
		}
	}

	fclose(fp);

	return 0;
}

void download_diagnostics_print()
{
	char value[256]={0};

	download_diagnostic_get("TCPOpenRequestTime", value);
	printf("TCPOpenRequestTime=[%s]\n", value);
	
}


int main(int argc, char *argv[])
{
	int index;

	//download_diagnostics_start();
	download_diagnostics_print();

    return 0;
}
